﻿using Sustainalytics.CDDB.DataConnector;
using Sustainalytics.Entities;
using Sustainalytics.SharedEntities.Corporate;
using Sustainalytics.SharedEntities.Interfaces.Enums;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;

namespace Sustainalytics.Governance.Synchronization
{

    public static class CorporateGovernanceCompanyProfilesQuery
    {
        public static IEnumerable<GovernanceCompanyProfile> Get(CorporateDataRepository corporateDataRepository)
        {
            return corporateDataRepository.ListCompaniesWithActiveResearch(ResearchFramework.CorporateGovernance,
                new List<Expression<Func<CorporateDetails, string>>>
                {
                    cd => nameof(cd.CompanyName)
                })
                .Where(x => !x.ResearchParentId.HasValue)
                .Select(cd => new GovernanceCompanyProfile
                {
                    Id = cd.Id,
                    CompanyName = cd.CompanyName
                });
        }
    }
}
